package com.cainaer.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cainaer.product.domain.ProductAttributeBindOption;
import com.cainaer.product.mapper.ProductAttributeBindOptionMapper;
import com.cainaer.product.service.IProductAttributeBindOptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 规格属性绑定表 服务实现类
 * </p>
 *
 * @author Tina
 * @since 2020-09-11
 */
@Service
public class ProductAttributeBindOptionServiceImpl extends ServiceImpl<ProductAttributeBindOptionMapper, ProductAttributeBindOption> implements IProductAttributeBindOptionService {

    @Autowired
    private ProductAttributeBindOptionMapper productAttributeBindOptionMapper;

    /**
     * 新增规格属性绑定
     *
     * @param productAttributeBindOption
     * @return
     */
    @Override
    public Integer insertProductAttributeBindOption(ProductAttributeBindOption productAttributeBindOption) {
        return productAttributeBindOptionMapper.insert(productAttributeBindOption);
    }

    /**
     * 编辑商品规格属性绑定
     *
     * @param productAttributeBindOption
     * @return
     */
    @Override
    public Integer editProductAttributeBindOption(ProductAttributeBindOption productAttributeBindOption) {
        return productAttributeBindOptionMapper.updateById(productAttributeBindOption);
    }

    /**
     * 通过规格ID 查询商品规格属性绑定数据
     *
     * @param attributeId
     * @return
     */
    @Override
    public List<ProductAttributeBindOption> selectProductAttributeBindOptionByAttributeId(Long attributeId) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("attribute_id", attributeId);
        return productAttributeBindOptionMapper.selectList(queryWrapper);
    }


}
